/**
 * @file timer.c
 * @author      JinChengLong (https://gitee.com/Datejin/)
 * @brief       定时器
 * @version     0.1
 * @date        2023
 * 
 * @copyright   Copyright © 2025 by JinChengLong 
 * 
 * All rights reserved.
 * Unauthorized copying, reproduction, or redistribution of this file via any medium is strictly prohibited.  
 * Proprietary and confidential.
 *   
 */



#include "timer.h"
 void timer_init(void)
{
	//ʱ��//
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2|RCC_APB1Periph_TIM3, ENABLE);			//��TIM2��ʱ��ʱ��
	TIM_InternalClockConfig(TIM2);									//ѡ��Ϊ72M�ڲ�ʱ�ӣ�Ĭ���ڲ�ʱ�ӣ�
	TIM_InternalClockConfig(TIM3);
	
	
	
	//ʱ����Ԫ����
	//��ʱƵ��=72M/��psc+1��/��ARR+1��
	
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
	TIM_TimeBaseInitStructure.TIM_ClockDivision =TIM_CKD_DIV1;		//TIM2 1��Ƶ
	TIM_TimeBaseInitStructure.TIM_CounterMode =TIM_CounterMode_Up;	//���ϼ���(���㵽��װֵ��
	TIM_TimeBaseInitStructure.TIM_RepetitionCounter =	0;				//�ظ���������ֵ���߼���ʱ����
	TIM_TimeBaseInitStructure.TIM_Prescaler	=7200-1;						//PSCԤ��Ƶ����ֵ(0��65535��72MƵ�ʱ�Ϊ10kHz
	TIM_TimeBaseInitStructure.TIM_Period =11800-1	;						//ARR�Զ���װ����ֵ�����ڣ���0��65535��
																			//����һ���ʱ��10k��Ƶ�ʼ���10000������һ��һ������
	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStructure);
	
	TIM_TimeBaseInitTypeDef a;
	a.TIM_ClockDivision =TIM_CKD_DIV1;		//TIM2 1��Ƶ
	a.TIM_CounterMode =TIM_CounterMode_Up;	//���ϼ���(���㵽��װֵ��
	a.TIM_RepetitionCounter =	0;				//�ظ���������ֵ���߼���ʱ����
	a.TIM_Prescaler	=7200-1;						//PSCԤ��Ƶ����ֵ(0��65535��72MƵ�ʱ�Ϊ10kHz
	a.TIM_Period =11000-1	;						//ARR�Զ���װ����ֵ�����ڣ���0��65535��
	TIM_TimeBaseInit(TIM3, &a);					
	
	
	TIM_Cmd(TIM2,ENABLE);									//��ʱ����������
	TIM_Cmd(TIM3,ENABLE );
}



































